The present invention is related to computer systems, and in particular to techniques for virtual memory mapping for efficient memory usage.
Conventional computer systems generally use a range of memory and storage options, from the fast and expensive to the slow and inexpensive. A typical system may have a limited amount of fast/expensive memory (e.g., DRAM) and a relatively larger amount of slow/inexpensive memory (e.g., hard disk). In some systems the fast memory is used like a cache, where only data currently in use by an application is kept in the fast memory. When the application needs to work on a different chunk of data, data can be moved out of the fast memory to the slow memory and a new data chunk can be brought into the fast memory.
In one conventional approach for managing memory, applications are aware of different types of memories and manage the movement of data between different types of memory. Each application typically keeps only a limited amount of data in the fast memory, with other data kept in the slow memory. Each application includes memory management logic to ensure that the fast memory is used only as needed, and unneeded data is moved to slow memory. The memory management is thus non-transparent to the applications and tends to complicate applications. Further, this approach may also result in less than optimal use of memory, because applications that share memory may not have a global view of the need and usage of memory by other applications.
To keep applications simple, a second approach using virtual memory allows for managing memory in a manner that is transparent to applications. Each application addresses a virtual memory space so that the real location of data (whether it is in the fast memory or the slow memory) may be hidden from the application. From the application's perspective, the application is allocated a set of virtual addresses and always references the same virtual address for data, and thus does not need not be aware of where the data actually resides in the system. Hence, data can be moved by other mechanisms between the various types of memory, based on need, without applications needing to manage or even know the physical location of the data.
Generally, conventional processors support virtual memory using fixed block (page) sizes, such as 4 KB pages. Typically, virtual memory is allocated to applications such that a minimum allocated block size is the same as the page size of the processor. For example, if a system employs different types of memory and uses a processor that supports 4 KB pages, then the smallest unit of memory that is allocated from any of the memories is 4 KB if application transparency is to be maintained, even if the application needs less than 4 KB of data. For example, if an application needs a smaller block of memory, say 512 B, then a 4 KB chunk of memory is allocated for the block so that application transparency is maintained. However, making the minimum allocated block size the same as the page size of the processor potentially wastes available memory and restricts the minimum allocated block size by an application to the page size of the processor.